package com.hgx.su.example.common.springboot.mongo.controller;

import com.hgx.su.example.common.springboot.mongo.dao.UserRepository;
import com.hgx.su.example.common.springboot.mongo.entity.AdminUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * Description:
 * author: HGX
 * DateTime: 2021-02-07 14:18
 */
@RestController
@RequestMapping("/adminUser")
public class Controller {

    @Autowired
    private UserRepository userRepository;

    @GetMapping("randomInsert")
    public void randomInsert() {
        AdminUser adminUser = new AdminUser();
        Random random = new Random();
        adminUser.setId(random.nextLong());
        adminUser.setUserId(UUID.randomUUID().toString());
        adminUser.setUserName(UUID.randomUUID().toString());
        userRepository.insert(adminUser);
    }

    @GetMapping("getAll")
    public List<AdminUser> getAll() {
        return userRepository.findAll();
    }


}
